# -*- coding: utf-8 -*-
from fastapi      import Request
from urllib.parse import unquote


async def dictionary(request: Request, allow_body: bool = True):
    data = {}

    try:
        data = await request.json()
    except:
        if not allow_body:
            return None

        body = await request.body()

        if body == b"":
            return None

        for param in unquote(body.decode()).split("&"):
            key, value = param.split("=")
            data[key]  = value

    return data
